<template>
     <el-form :model="tableForm" :rules="tableRule" ref="tableForm" label-width="120px">

       <el-form-item label="健康知识" prop="knowledge">
         <el-input size="small" v-model="tableForm.knowledge" auto-complete="off" placeholder="请输入健康知识"></el-input>
       </el-form-item>

       <el-form-item label="健康管理技巧" prop="skill">
         <el-input size="small" type="textarea" v-model="tableForm.skill" auto-complete="off" placeholder="请输入健康管理技巧"></el-input>
       </el-form-item>

       <el-form-item label="预防疾病方法" prop="way">
         <el-input size="small" type="textarea" v-model="tableForm.way" auto-complete="off" placeholder="请输入预防疾病方法"></el-input>
       </el-form-item>

     </el-form>
</template>

<script>

import {addData, updateData} from '@/api/education'

// 表单校验
const tableRule = {
  knowledge: [{ required: true, message: '请输入健康知识', trigger: 'blur' }]
};

export default {
  name: 'EducationEdit',
  props: {
    formData :{
      type: Object
    }
  },
  data() {
    return {
      tableForm: this.formData,
      tableRule: tableRule,
      visible: false,
    }
  },
  methods:{
    //表单保存事件
    submitForm() {
      this.$refs["tableForm"].validate(valid => {
        if (valid) {
          if(this.tableForm.id == ""){
            addData(this.tableForm).then(res => {
              if (res.message == "success" ) {
                this.$message({
                  type: 'success',
                  message: '新增成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          }else{
            updateData(this.tableForm).then(res => {
              if (res.message == "success" ) {
                this.$message({
                  type: 'success',
                  message: '修改成功！'
                });
                this.$emit("closeDialog", false);
              } else {
                this.$message({
                  type: 'info',
                  message: res.message
                });
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    clearForm(){
      this.$refs.tableForm.resetFields();
      this.$refs.tableForm.clearValidate();
    }
  }
}
</script>

<style scoped>


</style>
